{% extends "showinfo/base.html" %}

{% block content %}




    <div class="form-group">
        <label class="col-lg-3 control-label">手机号码</label>

        <div class="col-lg-4">
            <input type="number" class="form-control" name="phonenumber" id="phonenumber" placeholder="手机号码"/>
        </div>
        <div class="col-lg-4">
            <input type="button" class="btn btn-primary" value="查看" onclick="getdata()"></button>
        </div>
    </div>
    <br/>
    <br/>
    <br/>

    <div class="alert alert-success" role="alert" id="msg">


    </div>




    <script>
        String.format = function (src) {
            if (arguments.length == 0) return null;
            var args = Array.prototype.slice.call(arguments, 1);
            return src.replace(/\{(\d+)\}/g, function (m, i) {
                return args[i];
            });
        };
        function getdata() {
            var url = "{% url "getapis:phonenum" "gg" %}";

            var phonenumber = $("#phonenumber").val();
            if (phonenumber.length == 0) {
                phonenumber = "18710829912";
            }

            url = url.replace("gg", phonenumber);

            $.getJSON(url, function (result) {

                console.log(result);

                var body=result.showapi_res_body;
                if (body.ret_code == -1) {
                    alert(body.error_info);
                    return false;
                }

                var s = "运营商:{0}<br />省:{1}<br />市:{2}<br />";
                var res = String.format(s, body.name, body.prov, body.city);
                console.log(res);
                $("#msg").html(res);


            });

        }
        $(function () {
            getdata();

        });

    </script>




{% endblock %}